import createApp from './createApp';

const { app, router, store } = createApp();

export default (context) => {
  return new Promise((resolve, reject) => {

    router.push(context.url); // 让router主动调用去匹配对应的组件


    // 基本上只有在服务器端渲染时才会用到
    // 当 router.push 的执行异步方法的时候会执行 
    router.onReady(() => {
      const matchedComponents = router.getMatchedComponents();
      if (!matchedComponents.length) {
        return reject(new Error('no component matched'));
      }
      // 做meta服务器端渲染
      context.meta = app.$meta();
      resolve(app);
    });
  });
}